package com.blockmeta.bbs.minemodule.adapter;

import android.content.Context;
import android.content.Intent;
import androidx.annotation.Nullable;
import androidx.cardview.widget.CardView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.blockmeta.bbs.baselibrary.base.adapter.BaseAdapter;
import com.blockmeta.bbs.businesslibrary.constant.Constant;
import com.blockmeta.bbs.minemodule.R;
import com.blockmeta.bbs.minemodule.activity.HtmlInviteActivity;
import com.blockmeta.bbs.minemodule.pojo.AirDropPOJO;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * Created by author on 2018/7/11.
 */

public class AirDropListAdapter extends BaseAdapter<AirDropPOJO, BaseViewHolder> {
    private Context mContext;

    public AirDropListAdapter(int layoutResId, @Nullable List<AirDropPOJO> data, Context context) {
        super(layoutResId, data);
        mContext = context;
    }


    @Override
    protected void convert(BaseViewHolder helper, final AirDropPOJO item) {
        if (!TextUtils.isEmpty(item.getImg())){
            Glide.with(mContext).load(item.getImg()).into((ImageView) helper.getView(R.id.airdrop_img));
        }else {
            ImageView img = helper.getView(R.id.airdrop_img);
            img.setImageResource(R.drawable.yoona);
        }
        helper.setText(R.id.airdrop_title, item.getTitle());

        TextView date = helper.getView(R.id.airdrop_date);
        switch (item.isOpen()) {
            case 1:
                date.setText("已结束");
                date.setTextColor(mContext.getResources().getColor(R.color.vote_oval_gray));
                date.setBackground(mContext.getResources().getDrawable(R.drawable.shape_popup_oval_gray_stroke));
                break;
            case 2:
                date.setText("进行中");
                date.setTextColor(mContext.getResources().getColor(R.color.green_59AE4B));
                date.setBackground(mContext.getResources().getDrawable(R.drawable.shape_main_green_stroke));
                break;
            case 3:
                date.setText("预热中");
                date.setTextColor(mContext.getResources().getColor(R.color.base_color_red));
                date.setBackground(mContext.getResources().getDrawable(R.drawable.shape_popup_oval_red_stroke));
                break;
            default:
                break;
        }
        CardView mainView = helper.getView(R.id.airdrop_main);
        mainView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (item.isOpen() == 3) {
                    return;
                }
                Intent intent = new Intent(mContext, HtmlInviteActivity.class);
                intent.putExtra(Constant.ZERO, item.getUrl());
                intent.putExtra(Constant.ONE, item.getId()+"");
                mContext.startActivity(intent);
            }
        });
    }
}
